package com.mail.server.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mail.dubbo.api.PmsProductAttributeApi;
import com.mail.dubbo.api.PmsProductCategoryApi;
import com.mail.model.db.PmsProductCategory;
import com.mail.model.dto.ProductCategoryDto;
import com.mail.model.vo.ChildrenCategoryVo;
import com.mail.model.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PmsProductCategoryService {

    @DubboReference
    private PmsProductCategoryApi productCategoryApi;


    // 添加商品分类
    public void createCategory(ProductCategoryDto productCategoryDto) {
        productCategoryApi.createCategory(productCategoryDto);
    }

    // 删除商品分类
    public void deleteCategory(Integer categoryId) {
        productCategoryApi.deleteCategory(categoryId);
    }

    // 查询所有一级分类及子分类
    public List<ChildrenCategoryVo> queryWithChildrenCategory() {
        List<ChildrenCategoryVo> childrenCategoryVos = productCategoryApi.queryWithChildrenCategory();
        return childrenCategoryVos;
    }

    // 分页查询商品分类
    public PageResult queryCategoryList(Integer parentId, Integer pageNum, Integer pageSize) {
        PageResult pageResult = new PageResult();
        Page<PmsProductCategory> page = productCategoryApi.queryCategoryList(parentId,pageNum,pageSize);
        pageResult.setList(page.getRecords());
        pageResult.setPageNum(page.getCurrent());
        pageResult.setPageSize(page.getSize());
        pageResult.setTotalPage(page.getPages());
        pageResult.setTotal(page.getTotal());
        return pageResult;
    }

    // 修改导航栏显示状态
    public void changeNavStatus(List<Integer> ids, Integer navStatus) {
        productCategoryApi.changeNavStatus(ids,navStatus);
    }

    // 修改显示状态
    public void changeShowStatus(List<Integer> ids, Integer showStatus) {
        productCategoryApi.changeShowStatus(ids,showStatus);
    }

    // 修改商品分类
    public void changeCategory(Integer id, ProductCategoryDto productCategoryDto) {
        productCategoryApi.changeCategory(id,productCategoryDto);
    }

    // 根据id获取商品分类
    public PmsProductCategory queryCategoryById(Integer id) {
        PmsProductCategory pmsProductCategory = productCategoryApi.queryCategoryById(Long.valueOf(id));
        return pmsProductCategory;
    }
}
